#include "fifo.hpp"

int main()
{
    //1、等待serve运行，一定先是serve端先运行，因为要创建命名管道


    //2、以写的方式打开
    //如果写端没有打开，读端就会阻塞到open，直到写端打开，open才会返回
    int wfd = open(PATH, O_WRONLY);
    if(wfd < 0)
        cerr << "open_writed failed, errno code: " << errno << ", error message: " << strerror(errno) << endl;
    else
        cout << "open_writed success!" << endl;

    //3、写到管道里
    while(true)
    {
        string str;
        cout << "please inter you order:";
        getline(cin, str);
        if(str == "quit")
            break;
        int n = write(wfd, str.c_str(), str.size());
        if(n > 0)
        {
            cout << "client write success" << endl;
        }
        else if(n == 0)
        {
            cout << "client port quit" << endl;
            break;
        }
        else
        {
            cout << "write failed" << endl;
            break;
        }
    }

    //4、关闭写端
    //close(wfd);

    return 0;
}